package com.lm56.web.sys.service;

import com.lm56.common.MyMd5PasswordEncoder;
import com.lm56.web.sys.domain.UserDetail;
import com.lm56.web.sys.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by kelvin on 16/10/23.
 */
@Component
public class RegisterService {

    @Autowired
    UserMapper usermapper;

    public void register(UserDetail userDetail) {
        //获取盐值
        String salt = MyMd5PasswordEncoder.genSalt();
        //加密密码
        MyMd5PasswordEncoder encoder = new MyMd5PasswordEncoder();
        String encodedPwd = encoder.encodePassword(userDetail.getPassword(), salt);
        userDetail.setPassword(encodedPwd);
        userDetail.setSalt(salt);
        usermapper.addUser(userDetail);
    }


}
